﻿package com.xuanque.mahjongDice.display 
{
	
	import flash.display.*;
	import flash.events.*;
	import utils.transitions.*;
	
	import com.xuanque.mahjongDice.events.SimpleMouseEvent;
	import com.xuanque.mahjongDice.events.SimpleMouseEventHandler;
	
	/**
	 * ...
	 * @author DefaultUser (Tools -> 游戏结束显示列表...)
	 */
	public class GameResult extends Sprite
	{
		private var contentList:Sprite;
		private var list_length:uint;
		private var isTween:Boolean;
		
		public function GameResult() {
			
			init();
			
			addListener();
		}
		
		private function init():void {
			
			contentList = new Sprite();
			this.contentList.x = 0;
			this.contentList.y = -55;
			addChild(this.contentList);
			
		}
		
		
		private function addListener():void {
			
			this.gameResultBG.addEventListener(MouseEvent.MOUSE_DOWN, barHandler);
			this.gameResultBG.addEventListener(MouseEvent.MOUSE_UP, barHandler);
			//使用了自己定义的事件类,下面两行是自己定义的事件类的应用
			SimpleMouseEventHandler.register(this); //传入要作为侦听的对象
			this.addEventListener(SimpleMouseEvent.RELEASE_OUTSIDE, releaseHandler);
			this.buttonMode = false;
		}
		private function barHandler(event:MouseEvent):void {
			
			switch(event.type) {
				case MouseEvent.MOUSE_DOWN:
					this.startDrag();
					break;
				case MouseEvent.MOUSE_UP:
					this.stopDrag();
					break;
				
			}
			
		}
		private function releaseHandler(e:SimpleMouseEvent) {
			this.stopDrag();
		}
		
		
		
		
		/*
		 * @列表添加：addPlayerUser(_name:String,prev_grade:String,all_grade:String)
		 * 
		*/
		public function addPlayerUser(result_array:Array):void {
			
			var _length:uint = result_array.length;
			
			list_length = this.contentList.numChildren;
			if (list_length > 0) {
				
				this.removeAllItem();
			}
			
			
			
			var item:GameResultItem;
			var newX:int = -20;//间隔为32
			for (var i = 0; i < _length; i++) {
				
				item = new GameResultItem(result_array[i]);
				newX += 32
				item.y = newX;
				
				this.contentList.addChild(item);
				
			}
			
			
		}
		
		/*
		 * 
		 * @移除所有项
		*/
		public function removeAllItem():void {
			
			var count = this.contentList.numChildren;
			for (var i:int = 0; i <count; i++) {
				
				contentList.removeChildAt(0);
			}
			
		}
		
		
		
		/*
		 * 
		 * @移除列：removeItemAt(_text:String)
		
		public function removeItemAt(_name:String) {
			var count = contentList.numChildren;
			for (var i:int = 0; i <count; i++) {
				var item:GameResultItem = contentList.getChildAt(i) as GameResultItem;
				if (item._text == _name) {
					contentList.removeChild(item);
					//trace("removeItemAt  count = " + count);
					this.refresh();
					return;
				}
				
			}
			
		}
		
		private function refresh(){
			
			var count = contentList.numChildren;
			var newY:Number = -30;
			for (var i:int = 0; i <count; i++) {
				var item:GameResultItem = contentList.getChildAt(i) as GameResultItem;
				Tweener.addTween(item,{y:newY +30,time:0.5});
				//newY = item.y;
				newY +=30;
			}
			
			//trace("refresh  count = " + count);
		}
		*/
		
		
		
		
		
	}
	
}